﻿using Sys.Core;
using Sys.Core.Models.Dto;
using Sys.Core.Models.VO;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Web;
using MiniFox.Utility;
using MiniFox.Web.Filters;
using MiniFox.Web.Infrastructure;

namespace Sys.Controllers
{
    [NoCache, ValidationFilter, Area(GlobalConstants.AREA_NAME)]
    public class MenuController : AuthorizedController<IMenuService>
    {
        [HttpGet]
        public Response<IEnumerable<ITreeNode>> Query()
        {
            var treeNodes = this.Component.Query();
            return treeNodes.CreateResponse();
        }

        [HttpPost]
        public Response<MenuVo> Create([FromBody] MenuDto menu)
        {
            var result = this.Component.Create(menu);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<MenuVo> Update([FromBody] MenuDto menu)
        {
            var result = this.Component.Update(menu);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<string> Delete([FromBody] string menuPath)
        {
            string result = this.Component.Delete(menuPath);
            return result.CreateResponse();
        }

        [HttpGet]
        public Response<IEnumerable<MenuModuleVo>> Modules([FromQuery] string appId, [FromQuery] string menuId)
        {
            var result = this.Component.GetMenuModules(appId, menuId);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<IEnumerable<MenuModuleVo>> AddModules([FromBody] MenuModuleSet menuModuleSet)
        {
            var result = this.Component.AddMenuModules(menuModuleSet);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<IEnumerable<MenuModuleVo>> RemoveModules([FromBody] MenuModuleSet menuModuleSet)
        {
            var result = this.Component.RemoveMenuModules(menuModuleSet);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<IEnumerable<MenuModuleVo>> UpdateModule([FromBody] MenuModuleDto menuModule)
        {
            var result = this.Component.EditMenuModule(menuModule);
            return result.CreateResponse();
        }

        [HttpGet]
        public Response<IEnumerable<MenuLinkVo>> Links([FromQuery] string appId, [FromQuery] string menuId)
        {
            var result = this.Component.GetMenuLinks(appId, menuId);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<MenuLinkVo> CreateLink([FromBody] MenuLinkDto menuLink)
        {
            var result = this.Component.CreateLink(menuLink);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<MenuLinkVo> UpdateLink([FromBody] MenuLinkDto menuLink)
        {
            var result = this.Component.UpdateLink(menuLink);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<string> DeleteLink([FromBody] string data)
        {
            var result = this.Component.DeleteLink(data);
            return result.CreateResponse();
        }

    }
}
